<template>
	<view>
		<view class="nav-bar">
			<view class="bar-text" @click="goBack">
				<view class="align">
		
				</view>
				<text>返回</text>
			</view>
		</view>
		<view class="head">
			<scroll-view scroll-x class="bg-white nav">
				<view class="flex text-center">
					<view class="cu-item flex-sub" :class="index==TabCur?'text-red cur':''" v-for="(item,index) in list"
						:key="index" @tap="tabSelect" :data-id="index">
						{{item.name}}
					</view>
				</view>
			</scroll-view>
			<view class="card-menu">
				<view class="card-content" v-for="(item,index) in AllList" :key="index" @click="hover">
					<view class="c-content">
						<view class="c-head">
							<view class="head-text">
								<text>￥</text>
								{{item.discount}}元
							</view>
							<view class="head-bottom">
								{{item.desc}}-{{item.tag}}
							</view>
						</view>
						<view class="c-body">
							<view class="b-text">
								{{item.name}}
							</view>
							<view class="b-bottom">
								有效期：至{{item.endTime}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="footer-text">
			没有更多了
		</view>
	</view>
</template>

<script>
	import api from '../../static/request.js'
	export default {
		data() {
			return {
				isCard: false,
				TabCur: 0,
				status: '',
				scrollLeft: 0,
				list: [{
					name: '未使用'
				}, {
					name: '已使用'
				}, {
					name: '过期关闭'
				}],
				AllList: [],
			}
		},
		onShow() {
			this.getFirst()
		},
		onLoad(option) {
			console.log(option, '传递过来的参数')
			this.TabCur = option.sts
			// this.tabSelect(val)
		},
		methods: {
			// 点击的时候加上效果-背景颜色变深
			hover(){
				
			},
			goBack(){
			    uni.switchTab({
			    	url:'/pages/mine/mine'
			    })	
			},
			// 调取全部接口
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60;
				// console.log(this.TabCur)
				api.get('coupon/mylist?', {
					status: this.TabCur,
					page: 1,
					limit: 10
				}).then(res => {
					// console.log(res, '6666');
					uni.showLoading({
						title: '加载中...'
					});
					// 模拟异步数据请求
					setTimeout(() => {
						// 假设数据请求成功
						this.AllList = res.data.data.list;
						console.log(this.AllList, '8888888888')
						// 隐藏加载提示
						uni.hideLoading();
					}, 200);
				});
			},
			// 获取全部的列表
			getFirst() {
				console.log(this.TabCur)
				api.get('coupon/mylist?', {
					status: this.TabCur,
					page: 1,
					limit: 10
				}).then(res => {
					// console.log(res, '6666');
					uni.showLoading({
						title: '加载中...'
					});
					// 模拟异步数据请求
					setTimeout(() => {
						// 假设数据请求成功
						this.AllList = res.data.data.list;
						console.log(this.AllList, '8888888888')
						// 隐藏加载提示
						uni.hideLoading();
					}, 200);
				});
			}
		}
	}
</script>

<style>
	@import url('coupon.css');
</style>
